<template>
  <div class="aside_container">
    <div></div>
    <div class="nav_container">
      <div class="nav">
        <!--按钮-->
        <div class="btn">
            <div class="btn-item"></div>
            <div class="btn-item"></div>
            <div class="btn-item"></div>
        </div>
        <!--头像-->
        <div class="icon">
            <div class="icon-img" title="个人资料" @click="toUserInfo">
              <img :src="userData.avatar" alt="" />
            </div>
            <div class="icon-con">
              <h2 title="个人资料" @click="toUserInfo">{{ userData.username }}</h2>
              <div class="show_data">
                <div class="show_data_item">
                  <!-- 动态数据 -->
                  <span id="font_nt">{{userData.focus}}</span>
                  <span id="font_nt"> 粉丝</span>
                </div>
                <div class="show_data_item" @click="toMyPosts" style="cursor: pointer;">
                  <!-- 动态数据 -->
                  <span id="font_nt">{{userData.postNum}}</span>
                  <span id="font_nt"> 帖子</span>
                </div>
              </div>
            </div>
        </div>
        <div class="line"></div>

        <div class="menu">
            <div class="item newAllPosts" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-new"></i>
                </div>
                <div class="con">最新帖子</div>
                <div class="ricon"></div>
            </div>
            <div class="item officialPost" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-guanfangrenzheng1"></i>
                </div>
                <div class="con">官方发布</div>
                <div class="ricon"></div>
              </div>
              <div class="item" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-xuexi"></i>
                </div>
                <div class="con">学习交流</div>
                <div class="ricon"></div>
            </div>
            <div class="item" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-qinggan"></i>
                </div>
                <div class="con">情感吃瓜</div>
                <div class="ricon"></div>
            </div>
            <div class="item" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-sousuoleimufill"></i>
                </div>
                <div class="con">寻人寻物</div>
                <div class="ricon"></div>
            </div>
            <div class="item" @click="clickToIndex">
                <div class="light"></div>
                <div class="licon">
                  <i class="iconfont nt-shipinleimu"></i>
                </div>
                <div class="con">美食探店</div>
                <div class="ricon"></div>
            </div>
            <div class="sendPost">
              <el-button @click="toPublish" class="sendpost_bt" type="primary" size="large">
                发帖
              </el-button>
            </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import '@/assets/font/iconfont.css'
import { ref , onMounted } from 'vue';
import { useRouter } from 'vue-router'
// 引入pinia中的useStore库
import { useStore } from '@/stores/userData'
// 引入storeToRefs，使普通数据变为响应式数据
import { storeToRefs } from "pinia";
// 接收useStore
const store = useStore()
// 解构并使数据具有响应式
const { userData } = storeToRefs(store);
onMounted(()=>{
})
const router = useRouter()
const toUserInfo = () => {
  router.push('/user')
}
const toMyPosts = () => {
  let userId = localStorage.getItem('user')
  router.push({ path: '/', query: { posterId: userId}})
}
const toPublish = () => {
  router.push('/publishPost')
}
// 导航栏菜单跳转
const clickToIndex = (a) => {
  if(a.target.innerHTML==='最新帖子'){
    router.push("/")
    console.log(1);
  }else if(a.target.innerHTML==='官方发布'){
    router.push({ path: '/', query: { cls: '官方发布' }})
    console.log(2);
  }else if(a.target.innerHTML==='学习交流'){
    router.push({ path: '/', query: { cls: '学习交流' }})
    console.log(3);
  }else if(a.target.innerHTML==='情感吃瓜'){
    router.push({ path: '/', query: { cls: '情感吃瓜' }})
    console.log(4);
  }else if(a.target.innerHTML==='寻人寻物'){
    router.push({ path: '/', query: { cls: '寻人寻物' }})
    console.log(5);
  }else if(a.target.innerHTML==='美食探店'){
    router.push({ path: '/', query: { cls: '美食探店' }})
    console.log(6);
  }
}
</script>
<style scoped lang="scss">
*{
  color:#fff;
}
.aside_container{
  display: grid;
  grid-template-columns: 30% 70%;
  position:relative;
  height: 100vh;
}
.nav_container{
  display: relative;
}
.nav {
  width: auto;
  height: 90vh;
  position:absolute;
  top: calc(50% - 45vh);
  background: #5191E9;
  border-top-left-radius: 15px;
  border-bottom-left-radius: 15px;
  overflow: hidden;
  transition: 0.5s;
}
.btn {
  width: 60px;
  height: 10px;
  display: flex;
  justify-content: space-around;
  margin-left: 25px;
  margin-top: 25px;
}
.btn-item {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.btn-item:nth-child(1) {
  background: #eb5a56;
}
.btn-item:nth-child(2) {
  background: #f8bc33;
}
.btn-item:nth-child(3) {
  background: #6ad759;
}
.icon {
  width: 230px;
  height: 60px;
  margin-left: 25px;
  margin-top: 30px;
  display: grid;
  grid-template-columns: 1fr 2fr;
}
.icon-img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
  cursor: pointer;
}
.icon-img img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.icon-con {
  height: 60px;
  margin-left: 20px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap
}
.icon-con h2 {
  font-size: 24px;
  font-weight: 400;
  cursor: pointer;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap
}
.show_data{
  margin-top: 8px;
  height: 20px;
  width: 120px;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.show_data_item span{
  font-size: 18px;
}
#iconfont_nt{
  font-size: 14px;
}
#font_nt{
  font-size: 14px;
}
.line {
  width: 200px;
  height: 1px;
  background: rgba(245, 253, 255, 0.5);
  margin: 30px 33px;
  transition: 0.5s;
}
.title {
  width: 60px;
  margin-left: 25px;
  margin-bottom: 20px;
}
.title p {
  font-size: 14px;
}
.menu {
  width: 230px;
  margin-left: 25px;
  margin-top: 30px;
}
.item {
  display: flex;
  position: relative;
  transition: 0.5s;
  border-radius: 6px;
  cursor: pointer;
}
.item:hover {
  background: rgba(255, 255, 255, 0.1);
}
.licon {
  width: 60px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.con {
  width: 160px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: 0.5s;
  overflow: hidden;
  position: relative;
  left: -20px;
  opacity: 1;
}
.ricon {
  width: 60px;
  height: 50px;
  transition: 0.5s;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  opacity: 1;
}
.iconfont {
  font-size: 26px;
}
.ricon .iconfont {
  font-size: 20px;
  color: #62cb44;
}
.light {
  width: 6px;
  height: 50px;
  background: #eb5a56;
  position: absolute;
  left: -25px;
  transition: 0.5s;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  opacity: 0;
}
.item:hover .light {
  opacity: 1;
}
.serve {
  width: 230px;
  /*    background: rgba(98, 203, 68, 0.5);*/
  background: rgba(0, 0, 0, 0.7);
  margin-left: 25px;
  border-radius: 10px;
  overflow: hidden;
  transition: 0.5s;
}
.sendPost{
  // margin-top: 10px;
  margin-top: 80px;
}
.sendpost_bt{
  border-radius: 20px;
  background-color: #fff;
  color: #5191E9;
  width: 100%;
}
.sendpost_bt:hover{
  animation: pulse 0.5s;
}
</style>